package com.example.demos.service.impl;

import com.example.demos.dto.EmpAccessDTO;
import com.example.demos.mapper.ResetPassWordMapper;
import com.example.demos.service.ResetPassWordService;
import com.example.demos.util.EncryptionPassWord;
import com.example.demos.util.PageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

@Service
public class ResetPassWordServiceImpl implements ResetPassWordService {
    @Autowired
    private ResetPassWordMapper resetPassWordMapper;
    @Override
    public PageBean<List<EmpAccessDTO>> getEmpAccess(Integer page,Integer rows) {
        Page<EmpAccessDTO> page1 = PageHelper.startPage(page, rows);
        resetPassWordMapper.getEmpAccess();
        System.out.println(resetPassWordMapper.getEmpAccess());
        return new PageBean<>(page1.getTotal(), page1.getResult());
    }

    @Override
    public boolean resetPwd(BigInteger id, String newPwd) {
        if(newPwd!=null&& !newPwd.isEmpty()){
            String EncryptionPwd = EncryptionPassWord.generateSaltPassword(newPwd);
            resetPassWordMapper.resetPwd(id,EncryptionPwd);
            return true;
        }
        return false;
    }
}
